# Maintainer: Wu Zhenyu <wuzy01@qq.com>

_realname=scrcpy
pkgbase="mingw-w64-${_realname}"
pkgname="$MINGW_PACKAGE_PREFIX-${_realname}"
pkgver=1.25
pkgrel=1
pkgdesc='Display and control your Android device (mingw-w64)'
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/Genymobile/scrcpy'
license=('spdx:Apache-2.0')
depends=(
  "$MINGW_PACKAGE_PREFIX-ffmpeg"
  "$MINGW_PACKAGE_PREFIX-SDL2"
  "$MINGW_PACKAGE_PREFIX-libusb"
)
makedepends=(
  "$MINGW_PACKAGE_PREFIX-cc"
  "$MINGW_PACKAGE_PREFIX-pkgconf"
  "$MINGW_PACKAGE_PREFIX-meson"
)
source=("${_realname}-${pkgver}.tar.gz::$url/archive/v${pkgver}.tar.gz"
        "$url/releases/download/v${pkgver}/${_realname}-server-v${pkgver}")
sha256sums=('dfecc9dcffd45540bef88a7e346d37bead3665a5c868a5a95c5ec7bfed43ad07'
            'ce0306c7bbd06ae72f6d06f7ec0ee33774995a65de71e0a83813ecb67aec9bdb')

build() {
  mkdir -p "build-${MSYSTEM}" && cd "build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    --prefix="${MINGW_PREFIX}" \
    --buildtype release \
    -Dprebuilt_server="../${_realname}-server-v${pkgver}" \
    ../"${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/meson.exe compile
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson.exe install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}"/LICENSE -t \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
